var util = require('../../utils/common.js'); //引入公共JS


function selectNav() {
  //下拉菜单
  return ['hidden', 'hidden', 'hidden'];
}

Page({
  data: {
    showIcon: true,
    //显示返回键以及首页
    cityData: "全国",
    firstPerson1: '全部分类',
    firstPerson2: '推荐排序',
    firstPerson3: '距离最近',
    firstPerson4: '限时抢购',
    select_one: //二级菜单
    [{
      num: 11,
      name: "美食",
      index: "0-1"
    }, {
      num: 12,
      name: "休闲娱乐",
      index: "0-2"
    }, {
      num: 13,
      name: "本地生活",
      index: "0-3"
    }],
    select_one2: //二级菜单
    [{
      num: 21,
      name: "推荐排序",
      index: "1-1"
    }, {
      num: 22,
      name: "新品推荐",
      index: "1-2"
    }, {
      num: 23,
      name: "低价优先",
      index: "1-3"
    }, {
      num: 24,
      name: "销量最高",
      index: "1-4"
    }],
    select_one3: //二级菜单
    [{
      num: 31,
      name: "推荐排序",
      index: "2-1"
    }, {
      num: 32,
      name: "新品推荐",
      index: "2-2"
    }, {
      num: 33,
      name: "低价优先",
      index: "2-3"
    }],
    MBFlag: "true",
    SearchClose: true,
    //关闭搜索按钮
    SearchTo: false,
    //搜索按钮
    _num: '',
    //二级菜单
    tab_num: "",
    //一级菜单
    selectnav: selectNav(),
    cityFlag: true,
    //城市
    mengbanFlag: true,
    //蒙版
    searchFlag: true,
    //搜索
    wxcity: '',
    wxprovince: ''
  },
  onLoad: function (options) {},
  _onLoad: function (options) {},
  //关闭页面时隐藏城市弹框,关闭一级和二级菜单
  onShow: function () {
    //点击关闭二级列表
    var newselect = selectNav();
    newselect[0] = 'hidden';
    newselect[1] = 'hidden';
    newselect[2] = 'hidden';
  },
  listClick: function (e) {},
  //打开关闭城市
  onCloseCity: function (e) {
    this.setData({
      cityFlag: true
    });
  },
  searchValue: function (e) {
    //打开搜索
    var _data = e.detail.value;
    this.data.SearchValue = e.detail.value;
    var patt3 = /^[\u4e00-\u9fa5]{2,20}$/; //正则验证汉字不能少两个，不能多余20个

    this.setData({
      value: e.detail.value //保存输入框的值

    });

    if (_data == '') {
      this.setData({
        searchFlag: true,
        //关闭搜索蒙版
        SearchClose: true,
        SearchTo: false,
        //打开搜索图标
        value: "" //清空输入框的值

      });
    } else if (patt3.test(_data)) {
      this.setData({
        searchFlag: false,
        SearchClose: false,
        SearchTo: true
      });
    }
  },
  //点击关闭按钮关闭搜索框
  toClose: function () {
    this.setData({
      searchFlag: true,
      SearchClose: true,
      SearchTo: false,
      value: "" //清空输入框的值

    });
  },
  //关闭搜索
  onCloseSearch: function () {
    this.setData({
      searchFlag: true,
      SearchClose: true,
      SearchTo: false,
      value: "" //清空输入框的值

    });
  },
  clickTab: function (e) {
    //点击列表切换
    var index = parseInt(e.currentTarget.dataset.index);
    var newselect = selectNav();

    if (this.data.selectnav[index] == 'hidden') {
      newselect[index] = 'show';
      this.setData({
        MBFlag: false,
        //打开蒙版
        tab_num: e.target.dataset.tabnum
      });
    } else {
      newselect[index] = 'hidden';
      this.setData({
        MBFlag: true,
        //关闭蒙版
        tab_num: e.target.dataset.tabnum
      });
    } //设置为新的数组


    this.setData({
      selectnav: newselect
    });
  },
  mySelect: function (e) {
    //点击列表选择
    var index = parseInt(e.currentTarget.dataset.index);
    var newselect = selectNav();
    newselect[index] = 'hidden';
    var index2 = e.currentTarget.dataset.index.split('-')[0];
    this.setData({
      selectnav: newselect,
      //隐藏下拉框
      MBFlag: true,
      //关闭蒙版
      _num: e.target.dataset.num
    });

    if (index2 == 0) {
      this.setData({
        firstPerson1: e.target.dataset.text
      });
    } else if (index2 == 1) {
      this.setData({
        firstPerson2: e.target.dataset.text
      });
    } else if (index2 == 2) {
      this.setData({
        firstPerson3: e.target.dataset.text
      });
    }
  },
  tapMenuHide: function (e) {
    //点击蒙版关闭蒙版和二级菜单
    var index = parseInt(e.currentTarget.dataset.index);
    var newselect = selectNav();
    newselect[index] = 'hidden';
    this.setData({
      selectnav: newselect,
      MBFlag: true //关闭蒙版

    });
  },
  // 获取滚动条当前位置
  onPageScroll: function (e) {
    if (e.scrollTop > 100) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },
  //回到顶部
  goTop: function () {
    util.goTop();
  }
});